package com.itheima.device.controller;


import com.itheima.device.pojo.Device;
import com.itheima.device.pojo.DeviceInfo;
import com.itheima.device.service.DeviceInfoService;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//开启跨越请求操作
@RequestMapping("/deviceInfo")
public class DeviceInfoController {

    @Autowired
    private DeviceInfoService deviceInfoService;

    /**
     * 根据设备使用说明id查询
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public  Result findByDeviceInfo (@PathVariable  Integer id) {
        DeviceInfo deviceInfo = null;
        try {
            deviceInfo = deviceInfoService.findDeviceInFoById(id);
            return new Result(true, StatusCode.OK, "设备详情查询成功", deviceInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "设备详情查询失败");

        }

    }

    /**
     * 修改设备使用说明书
     * @param deviceInfo
     * @return
     */
    @PutMapping("/update")
    public Result updateDevice(@RequestBody DeviceInfo deviceInfo  ){
        try {
            deviceInfoService.updateDeviceInfo(deviceInfo);
            return new Result(true,StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"修改失败");
        }


    }


    /*@PostMapping("/addDeviceAndDeviceInfo")
    public Result addDeviceAndDeviceInfo(@RequestBody Device device){
        try {
            deviceInfoService.addDeviceAndDeviceInfo(device);
            return new Result(true,StatusCode.OK,"新增设备和设备使用说明书成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"新增设备和设备使用说明书失败");
        }


    }*/






}
